﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sys.WebRes.Data
{
    public partial class Language
    {
        public static Dictionary<int, Language> Map = new Dictionary<int, Language>();

        public static Language CN = new Language(1, "中文简体", "CN", "中文简体", 1);
        public static Language ZH = new Language(2, "中文繁体", "ZH", "中文繁体", 2);
        public static Language EN = new Language(3, "英文",    "EN", "英文", 3);
        public static Language JP = new Language(4, "日文",    "JP", "日文", 4);

        public static void Initialize(ResourceSysEntities db)
        {
            var list = db.LanguageTBL.ToList();
            if (list.Count > 0)
            {
                list.ForEach(p =>
                {
                    Map[p.ID].Name = p.Name;
                    Map[p.ID].Abbr = p.Abbr;
                    Map[p.ID].Explain = p.Explain;
                    Map[p.ID].OrderNo = p.OrderNo;
                });
            }
            else
            {
                Array.ForEach(Map.Values.ToArray(), p =>
                {
                    db.AddToLanguageTBL(p);
                });
            }
        }

        private Language(int id, string name, string abbr, string explain, int orderNo)
        {
            this.ID = id;
            this.Name = name;
            this.Abbr = abbr;
            this.Explain = explain;
            this.OrderNo = orderNo;

            Map.Add(id, this);
        }

        public Language() { }
    }
}
